#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

from page import *
from naviguation import *
from admin import *
import cgi

form = cgi.FieldStorage()
msg=""

print u"Content-type: text/plain"
print

if form.has_key(u"session"): 
   session = form[u"session"].value  
else:
   msg+="<br/>*** Champ session vide ! ***"

if form.has_key(u"page_id"): 
   page_id = form[u"page_id"].value  
else:
   msg+="<br/>*** Champ page_id vide ! ***"

if form.has_key(u"page_title"): 
   page_title = form[u"page_title"].value  
else:
   msg+="<br/>*** Champ page_title vide ! ***"

if form.has_key(u"nav_id"): 
   nav_id = form[u"nav_id"].value  
else:
   msg+="<br/>*** Champ nav_id vide ! ***"

if form.has_key(u"nav_name"): 
   nav_name = form[u"nav_name"].value  
else:
   msg+="<br/>*** Champ nav_name vide ! ***"

if form.has_key(u"nav_title"): 
   nav_title = form[u"nav_title"].value  
else:
   msg+="<br/>*** Champ nav_title vide ! ***"

if form.has_key(u"nav_parent_id"): 
   nav_parent = form[u"nav_parent_id"].value  
else:
   msg+="<br/>*** Champ nav_parent vide ! ***"   

if form.has_key(u"nav_position"): 
   nav_position = form[u"nav_position"].value  
else:
   msg+="<br/>*** Champ nav_position vide ! ***"

if form.has_key(u"nav_onclick"): 
   nav_onclick = form[u"nav_onclick"].value  
else:
   msg+="<br/>*** Champ nav_onclick vide ! ***"   

if form.has_key(u"nav_selected"): 
   nav_selected = form[u"nav_selected"].value  
else:
   msg+="<br/>*** Champ nav_selected vide ! ***"

if form.has_key(u"page_content"): 
   page_content = form[u"page_content"].value  
else:
   msg+="<br/>*** Champ page_content vide ! ***"   


# UPDATE DATA
pg=Page()
if pg.setPage(page_id, page_title, page_content, nav_id):
  nav=Nav()
  if nav.setOneElement(nav_id, nav_name, nav_title, nav_parent, nav_position, nav_onclick, nav_selected, page_id):
    msg+="<br/>La page %s (ID:%s) &agrave; &eacute;t&eacute; mise a jour avec succ&egrave;s !" % (page_title, page_id)
  else:
    msg+="<br/>Impossible de mettre le menu de la page %s (ID:%s) &agrave; jour !" % (page_title, page_id)
else:
  msg+="<br/>Impossible de mettre la page %s (ID:%s) &agrave; jour !" % (page_title, page_id)

# GET ADMIN CONTENT
adm=AdminCms()
print adm.getPageHeader()
print adm.getAdminMenu()
print "<tr><td colspan='3'><div id='active_page'><b>%s</b></div></td></tr>" % msg
print adm.getPagesList()
print adm.getPageFooter()
